<?php

include('XMLImporter.php');

$dbConfig = Array
(
    'dbtype' => "MYSQL",
    'host' => "localhost",
    'database' => "test",
    'user' => "root",
    'password' => "root"
);

$fieldsMap = Array
(
    'bus_id' => Array(Type::TYPE => ValueType::VALUE,
        "value" => "2"),

    'sales_title' => Array(Type::TYPE => ValueType::TAG,
        "value" => "short_title"),

    'sales_desc' => Array(Type::TYPE => ValueType::TAG,
        "value" => "description",
        "dependsOn" => "price"),

    'sale_starts' => Array(Type::TYPE => ValueType::TAG,
        "value" => "offer_starts_at",
        "default" => date("Y.m.d"),
        "action" => "processDate"),

    'sale_ends' => Array(Type::TYPE => ValueType::TAG,
        "value" => "offer_ends_at",
		"default" => date("Y.m.d", strtotime("+1 month")),
        "action" => "processDate"),

    'not_sure' => Array(Type::TYPE => ValueType::VALUE,
        "value" => "1"),

    'google_map' => Array(Type::TYPE => ValueType::VALUE,
        "value" => "online"),

   'website' => Array(Type::TYPE => ValueType::VALUE,
		"value" => "http://www.livingsocial.com.au"),

    'photo' => Array(Type::TYPE => ValueType::VALUE,
        "value" => "livingsocial-logo.png"),

    'thumbnail' => Array(Type::TYPE => ValueType::VALUE,
        "value" => "livingsocial-logo.png"),

    'affiliate_link' => Array(Type::TYPE => ValueType::TAG,
        "value" => "url",
		"action" => "getAffilateLink"),

    'affiliate_product_id' => Array(Type::TYPE => ValueType::TAG,
        "value" => "id",
        "key" => "true"),

    'active' => Array(Type::TYPE => ValueType::VALUE,
        "value" => "1"),

    'is_featured' => Array(Type::TYPE => ValueType::VALUE,
        "value" => "0"),

    'sale_keyword' => Array(Type::TYPE => ValueType::TAG,
        "value" => "long_title"),

    'price' => Array(Type::TYPE => ValueType::TAG,
        "value" => "options->price"),
);

$imagesFieldsMap = Array(
    'sales_id' => Array(Type::TYPE => ValueType::VALUE,
        "value" => "This id will be set in action method",
        "action" => "getSaleIdFromItem"),

	'file_title' => Array(Type::TYPE => ValueType::TAG,
        "value" => "short_title"),
		
    'image_title' => Array(Type::TYPE => ValueType::TAG,
        "value" => "short_title"),

	'extension' => Array(Type::TYPE => ValueType::VALUE,
        "value" => "jpg"),	
		
    'image_path' => Array(Type::TYPE => ValueType::TAG,
        "value" => "images->size700",
        "action" => 'downloadImage'));

//$xmlFilePath = "deals.xml";
//$imagesFolder = "C:/wamp/www/uploads/business/";
$xmlFilePath = "small_deals.xml";
$imagesFolder = "./images/";

$importer = new XMLImporter($dbConfig, $fieldsMap, $xmlFilePath, $imagesFolder, "deals");
list($uniqueItems, $firstItemId, $lastItemId) = $importer->parseFile(Constants::TBL_SALES, Constants::TBL_SALES_ID);

$uniqueItemsCopy = $importer->copyArray($uniqueItems);

$importer->mapAdditionalTable($uniqueItemsCopy, $firstItemId, $lastItemId, $imagesFieldsMap, Constants::TB_SALES_IMAGE, Constants::TBL_SALES_ID);
?>